﻿using System;
using System.Drawing;

namespace WindowsAPI
{
    [Serializable]
    public class MouseButtonEventArgs : MouseEventArgs
    {
        public static MouseButtonEventArgs FromMouseEventArgs(MouseEventArgs args) { return new MouseButtonEventArgs(args); }

        [Serializable, Flags]
        public enum ButtonType : byte { Left = 0, Middle = 1, Right = 2 }

        [Serializable]
        public enum DirectionType : byte { Down = 0, Up = 1 }

        public ButtonType Button { get; private set; }
        public DirectionType Direction { get; private set; }
        public Point Position { get { return Struct.Point; } }

        public MouseButtonEventArgs() { }

        private MouseButtonEventArgs(MouseEventArgs args)
            : base(args)
        {
            switch(args.Msg)
            {
                case Mouse.Message.LeftButtonDown:
                    Button = ButtonType.Left;
                    Direction = DirectionType.Down;
                    break;
                case Mouse.Message.LeftButtonUp:
                    Button = ButtonType.Left;
                    Direction = DirectionType.Up;
                    break;
                case Mouse.Message.RightButtonDown:
                    Button = ButtonType.Right;
                    Direction = DirectionType.Down;
                    break;
                case Mouse.Message.RightButtonUp:
                    Button = ButtonType.Right;
                    Direction = DirectionType.Up;
                    break;
                case Mouse.Message.MiddleButtonDown:
                    Button = ButtonType.Middle;
                    Direction = DirectionType.Down;
                    break;
                case Mouse.Message.MiddleButtonUp:
                    Button = ButtonType.Middle;
                    Direction = DirectionType.Up;
                    break;
            }
        }
    }
}